package com.wing.area.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.area.dao.AreaDao;
import com.wing.area.model.entity.Area;
import com.wing.area.model.response.AreaVO;
import com.wing.area.service.AreaService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AreaServiceImpl extends ServiceImpl<AreaDao, Area> implements AreaService {

	@Override
	public List<AreaVO> getProvinceList() {
		QueryWrapper<Area> queryWrapper = new QueryWrapper<Area>();
		queryWrapper.eq("level", 1);
		List<Area> list = this.baseMapper.selectList(queryWrapper);
		List<AreaVO> areas = new ArrayList<AreaVO>();
		for (Area area : list) {
			areas.add(new AreaVO(area));
		}
		return areas;
	}

	@Override
	public List<AreaVO> getCityList(Integer parentId) {
		QueryWrapper<Area> queryWrapper = new QueryWrapper<Area>();
		queryWrapper.eq("parentid", parentId);
		List<Area> list = this.baseMapper.selectList(queryWrapper);
		List<AreaVO> areas = new ArrayList<AreaVO>();
		for (Area area : list) {
			areas.add(new AreaVO(area));
		}
		return areas;
	}

	@Override
	public List<AreaVO> getAreaList(Integer parentId) {
		QueryWrapper<Area> queryWrapper = new QueryWrapper<Area>();
		queryWrapper.eq("parentid", parentId);
		List<Area> list = this.baseMapper.selectList(queryWrapper);
		List<AreaVO> areas = new ArrayList<AreaVO>();
		for (Area area : list) {
			areas.add(new AreaVO(area));
		}
		return areas;
	}

}